home *** CD-ROM | disk | FTP | other *** search
- Path: news.infi.net!usenet
- From: nngis@norfolk.infi.net (Greg DiGiorgio)
- Newsgroups: comp.lang.c
- Subject: Re: How to copy from Array to Array ?
- Date: 5 Feb 1996 14:36:35 GMT
- Organization: Customer of InfiNet
- Message-ID: <4f54lj$b34@nw002.infi.net>
- References: <4f3ec3$3vp5@unix1.sncc.lsu.edu>
- Reply-To: nngis@norfolk.infi.net
- NNTP-Posting-Host: h-talisman.norfolk.infi.net
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.99.3
-
- In article <4f3ec3$3vp5@unix1.sncc.lsu.edu>, garaja@unix1.sncc.lsu.edu
- says...
- >
- >Hello Everybody:
- > I have a simple question on using Arrays and Pointers. Let's say
- >that i have two arrays declared as,
- > double Array1[15000], and char Array2[15000].
- > How do i sequentially copy elements from Array1 to Array2 using
- "sprintf"
- >and "pointers" and how i can print the values in Array2. Any suggestions
- >will be appreciated.
- >
- >RAJABHUSHAN CHERUKURI (RAJ)
- >LOUISIANA STATE UNIVERSITY
- >garaja@unix1.sncc.lsu.edu
-
- First, the size of Array1 might be 60K, but the size of Array2 is 15K,
- so you need a new Array2.
-
- #include <string>
- #include <stdio.h>
- double array1[15000];
- char array2[15000][20]; /* assume 14 dig precision, decimal, leading
- zero, a NULL,a dn extra room just in case */
-
- main() {
- int i;
- int res;
- ... blah-blah ... /* assume you init "array1" here */
- for (i=0; i<10; i++) {
- res=sprintf(&(array2[i][0]),"%lf",array1[i]);
- if (res == EOF) printf("Error on #%d\n",i);
- else printf("Converted: %s",&(array2[i][0]));
- }
- }
-
- Hope this helps,
- Greg DiGiorgio
-
- "The meek shall inherit the earth" - who says nice guys finish last?
-
-